home *** CD-ROM | disk | FTP | other *** search
-
- /*
- * $Header: host.c,v 3.0 91/05/17 16:14:06 jrd Rel $
- * Author: J. Davin
- * Copyright 1988, 1989, Massachusetts Institute of Technology
- * See permission and disclaimer notice in file "notice.h"
- */
-
- #include <notice.h>
-
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <arpa/inet.h>
- #include <netdb.h>
- #include <stdio.h>
-
- #include <local.h>
- #include <host.h>
-
- long hostAddress (string)
-
- char *string;
-
- {
- struct hostent *hp;
- long host;
-
- host = (long) inet_addr (string);
- if (host == -1L) {
- hp = gethostbyname (string);
- if (hp == NULL) {
- return (-1);
- }
- else if (hp->h_addrtype != AF_INET) {
- return (-1);
- }
- else {
- host = 0L;
- bcopy (hp->h_addr, (char *) & host,
- sizeof (host));
- }
- }
- return (host);
- }
-
- int hostString (result, n, host)
-
- char *result;
- int n;
- long host;
-
- {
- struct hostent *hp;
- struct in_addr in;
- int k;
- char *cp;
-
- hp = gethostbyaddr ((char *) & host, (int) sizeof (host),
- (int) AF_INET);
- if (hp != NULL) {
- k = strlen (hp->h_name);
- if (k > n) {
- return (0);
- }
- else {
- (void) strcpy (result, hp->h_name);
- return (k);
- }
- }
- else {
- (void) bzero ((char *) & in, (int) sizeof (in));
- in.s_addr = (u_long) host;
- cp = inet_ntoa (in);
- if (cp == (char *) NULL) {
- return (0);
- }
- else if ((k = strlen (cp)) > n) {
- return (0);
- }
- else {
- (void) strcpy (result, cp);
- return (k);
- }
- }
- }
-
-